package com.lemon.smartsafetynew.ui.fragment.base;

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

import com.lemon.smartsafety.R;

/**
 * Created by SlienceDut on 2015/12/12.
 */
public abstract class ToolbarBaseFragment extends BaseFragment {
    public Toolbar mToolBar;

    @Nullable
    public TextView mMainTitle;

    protected abstract int getTitle();

    @Override
    protected void initViews() {
        mToolBar = getViewById(R.id.toolbar);
        mMainTitle = getViewById(R.id.main_title);
        initToolbar();
        setHasOptionsMenu(true);

    }

    protected void initToolbar() {
        ((AppCompatActivity) getActivity()).setSupportActionBar(mToolBar);
        //((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); //delete by Andrew.yin 2017/9/18
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
        mMainTitle.setText(this.getTitle());
        ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("");
        //mToolBar.setNavigationIcon(R.mipmap.ic_menu_white); //delete by Andrew.yin 2017/9/18

    }

    public void setTitle(String title){
        mMainTitle.setText(title);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("");
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }


    @Override
    protected void getBaseArguments() {

    }
}
